/*$("#id").blur(checkUserid);
function checkUserid(){
    var id = $("#id").val()

    if(id==""||id==null){
        $("#id").addClass("change").prop("placeholder","手机号不能为空")
        return false;
    }else if(!/^[1]([3-9])[0-9]{9}$/.test(id)){
        $("#id").val("")
        $("#id").addClass("change").prop("placeholder","手机号格式错误")
        return false;
    }
    return true;

}*/

$("#pwd").blur(checkUserpassword);
function checkUserpassword(){
    var password = $("#pwd").val()

    if(password==""||password==null){
        $("#pwd").addClass("change").prop("placeholder","密码不能为空")
        return false;
    }else if(!/^[a-zA-Z]\w{5,9}$/.test(password)){
        $("#pwd").val("")
        $("#pwd").addClass("change").prop("placeholder","密码格式错误")
        return false;
    }
    return true;

}
$(".login-btn").click(function (){

    $.ajax({
        type:"post",
        url:"../customer/login",
        data:{
            customerName:$(".phone-name").val(),
            customerPassword:$(".phone-pwd").val()
        },
        success:function (result){
            console.log("result:" + result);
            //保存信息到本地，里面都 token
            var token = result.data;
            console.log("token:" + token);

            localStorage.removeItem("token");
            localStorage.setItem("token",token);
            window.location.href = "../index.jsp";
        }
    })
})

$(function(){
    $(".login-message ").click(function(){
        $(".phone").hide();
        $(".message").show();
        console.log($(".phone"));
    })
})

$(function(){
    $(".login-phone ").click(function(){
        $(".message").hide();
        $(".phone").show();
        console.log($(".phone"));
    })
})

var button = document.getElementById('loginCodeBtn');
button.onclick = function (){
    button.disabled = 'disabled';
    var time = 60;
    var timer = setInterval(function (){
        if (time == -1){
            clearInterval(timer)
            button.disabled = '';
            button.value = '点击获取';
        }else {
            button.value = time + 's';
            time--;
            console.log("倒计时开始");
        }
    },1000)
}
var sms = "";
//发送验证码
$(".yanzheng-btn").click(function (){
    sendCode()
})
function sendCode(){
    var customerTel = $("#id").val();
    console.log("登录的手机号:"+customerTel);
    if (customerTel!=""){
        $.ajax({
            url: "../customer/loginSend",
            type: "get",
            async: false,
            data:{
                "phone": customerTel
            },
            success:function (result){
                console.log("...............");
                console.log(result)
                sms = result.data;
                console.log(typeof result);
                //sms = JSON.stringify(result).slice(52,58);
                //console.log(typeof sms[2]);
                console.log(sms);
                console.log("code:"+sms);

                // layer.msg("验证码已发送");
            }
        });
        return sms;
    }else {
        $("#loginfail1").text("请输入手机号")
        return false;
    }
}
//验证登录提交
$(".loginCode-btn").click(function (){
    loginByMsg()
})
function loginByMsg(){
    $.ajax({
        type: "post",
        url: "../customer/loginByMsg",
        data:{
            customerTel: $("#id").val()
        },
        success:function (result){
            console.log("result=========="+result);
            var phoneId = $("#id")
            var code = $(".message-yanzheng-text").val();
            console.log(code)
            console.log(sms)
            if (result.resultCode !=200){
                console.log("该手机用户不存在")
            }else if (code==""){
                $("#loginfail1").text("请输入验证码")
            }else if (sms !=code){
                $("#loginfail1").text("验证码错误")
            }else {
                var token = result.data;
                console.log("token=============="+token);
                localStorage.setItem("token",token);
                window.location.href = "../index.jsp";
            }
        }
    })
}
    //登录提交
    $(".login-btn").on("click",function (){
        var data = {};
        data.mobile = $.trim($("#id").val())
        $.ajax({
            url: getBasePath()+"/customer/login",
            async : true,
            type: "post",
            dataType: "text",
            data: data,
            success: function (data) {
                if(data == 'success'){
                    window.location.href = "../index.jsp";
                }
                alert(data);
            }
        });
    })




